import dotenv from 'dotenv'
import { createBot, createProvider, createFlow, addKeyword, utils } from '@builderbot/bot'
import { MysqlAdapter as Database } from '@builderbot/database-mysql'
import { BaileysProvider as Provider } from '@builderbot/provider-baileys'

const PORT = process.env.PORT ?? 3008

const flow = addKeyword([])
.addAction(async (_, { flowDynamic }) => {
    console.log(_)
    return flowDynamic('Buenas! ¿Cual es tu nombre?')
})

const main = async () => {
	const env = dotenv.config().parsed // 环境参数

    const adapterFlow = createFlow([flow])

    const adapterProvider = createProvider(Provider)

    const adapterDB = new Database({
        host: env.MYSQL_DB_HOST,
        user: env.MYSQL_DB_USER,
        database: env.MYSQL_DB_NAME,
        password: env.MYSQL_DB_PASSWORD,
    })

    const { handleCtx, httpServer } = await createBot({
        flow: adapterFlow,
        provider: adapterProvider,
        database: adapterDB,
    })

    httpServer(+PORT)
}

main()
